package com.weixin.demo.core.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

@Slf4j
public class InputStreamToStringUtils {

    public static String streamToString(InputStream is){
        String data = null;
        ByteArrayOutputStream baos = null;
        try {
            baos   =   new   ByteArrayOutputStream();
            int  i = -1;
            while((i=is.read())!=-1){
                baos.write(i);
            }
            baos.flush();
            data = baos.toString();

            baos.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            log.error("inputStreamToStringUtils",e);
        }finally{
            try {
                if(baos != null){baos.close();}
            } catch (Exception e2) {
                log.error("inputStreamToStringUtils",e2);
            }
        }
        return data;
    }
}
